package aaaPKg;

import java.awt.event.KeyEvent;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.attilax.concur.TaskUtil;
import com.attilax.device.KeyboardUtil;
import com.attilax.gui.WinUtil;
import com.attilax.io.filex;

public class geneTxts {

	private int startIdx;

	public static void main(String[] args) {

		geneTxts c = new geneTxts();
		c.startIdx = 1;
		c.exe();
		// c.act();
		// c. mx.mouseMove(750,511);
		// c.gotoPubPage2();
		// click txt

		// return this;
	}

	MouseUtil mx = new MouseUtil();
	KeyboardUtil keyboardUtil = new KeyboardUtil(mx.robot);

	private void exe() {

		String oriDir = "C:\\00yuntonxon_doc\\圣经箴言500句.txt";
		List<String> li = filex.read2list(oriDir, "gbk");
		int n = 0;
		for (String string : li) {
			n++;
			if (n < startIdx)
				continue;
			try {
				act();
				gotoPubPage();
				// click txt
				mx.mouseMove(550, 491);
				mx.click();
				keyboardUtil.keyPressString(" 每日心灵鸡汤：" + string);
				TaskUtil.sleep_sec(3);
				// if("1".equals("1"))
				// return;
				mx.mouseMove(550, 671); // title
				mx.click();
				
				try {
					keyboardUtil.keyPressString("t" + string.substring(0, 10));
				} catch (StringIndexOutOfBoundsException e) {
					keyboardUtil.keyPressString("t" + string);
				} catch (Exception e) {
					keyboardUtil.keyPressString("t" + filex.getUUidName());
				}

				submit();
				System.out.println(string);
			} catch (Exception e) {
				e.printStackTrace();
			}

			// return;
		}
	}

	private void act() {
		new WinUtil().WinActivate("新增短信模板 - 360安全浏览器");
		new WinUtil().WinActivate("短信模板 - 360安全浏览器");
		TaskUtil.sleep_sec(1);

	}

	private void gotoPubPage2() {
		mx.mouseMove(1200, 290);
		mx.click();
		TaskUtil.sleep_sec(3);
	}

	private void gotoPubPage() {
		keyboardUtil.keyPress(KeyEvent.VK_F6);
		String url = "http://www.yuntongxun.com/member/smsTemplate/toAdd";

		// string="xx";
		keyboardUtil.keyPressString(url);
		keyboardUtil.keyPress_enter();
		TaskUtil.sleep_sec(3);
	}

	public static Logger logger = LoggerFactory.getLogger(YuntonxunPubber.class);

	private void submit() {
		mx.mouseMove(420, 740);
		// if("1".equals("1"))
		// return;
		mx.click();
		logger.info("--submit doc finish");
		TaskUtil.sleep_sec(3); // submit
		mx.mouseMove(750, 511); // confirm
		mx.click();
		TaskUtil.sleep_sec(3);
	}

}
